---@diagnostic disable: undefined-global

--- 磐心技能
--- 锁定技，你脱离濒死状态后，防止你本回合受到的伤害。
--- 使用fk.AfterDying事件检测脱离濒死状态，使用fk.DamageInflicted事件防止伤害
local panxin = fk.CreateSkill{
  name = "lvshi__panxin",
  tags = { Skill.Compulsory },
}

-- 监听脱离濒死状态事件（通过AfterDying事件来判断）
panxin:addEffect(fk.AfterDying, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(panxin.name) and player.hp > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 标记防止本回合伤害
    room:addPlayerMark(player, "@@panxin_prevent-turn")
  end,
})

panxin:addEffect(fk.DamageInflicted, {
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(panxin.name) and player:getMark("@@panxin_prevent-turn") > 0
  end,
  on_use = function(self, event, target, player, data)
    -- 防止伤害
    data:preventDamage()
  end,
})


Fk:loadTranslationTable{
  ["lvshi__panxin"] = "磐心",
  [":lvshi__panxin"] = "锁定技，你脱离濒死状态后，防止你本回合受到的伤害。",
  ["@@panxin_prevent-turn"] = "防止伤害",
  
  ["$lvshi__panxin1"] = "磐石之心，不可动摇！",
  ["$lvshi__panxin2"] = "心如磐石，坚不可摧！",
}

return panxin